package com.peko.es.config;

import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.elasticsearch.client.ClientConfiguration;
import org.springframework.data.elasticsearch.client.RestClients;
import org.springframework.data.elasticsearch.config.AbstractElasticsearchConfiguration;

/**
 * @author Peko
 */
@Configuration
public class RestClientConfig extends AbstractElasticsearchConfiguration {

    /**
     * 用这个client来替换transportClient(9300)对象
     * @return
     */
    @Override
    @Bean
    public RestHighLevelClient elasticsearchClient() {
        //定义客户端配置对象 RestClient 9200
        final ClientConfiguration clientConfiguration = ClientConfiguration.builder()
                .connectedTo("192.168.58.132:9200")
                .build();
        //通过RestClient对象创建
        return RestClients.create(clientConfiguration).rest();
    }
}

